﻿using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbTranslationTest and is intended
    ///     to contain all TmdbTranslationTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbTranslationTest
    {
        /// <summary>
        ///     A test for TmdbTranslation Constructor
        /// </summary>
        [TestMethod]
        public void TmdbTranslationConstructorTest()
        {
            var target = new TmdbTranslation();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for EnglishName
        /// </summary>
        [TestMethod]
        public void EnglishNameTest()
        {
            var target = new TmdbTranslation();
            string expected = Guid.NewGuid().ToString();
            string actual;
            target.EnglishName = expected;
            actual = target.EnglishName;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Iso639_1
        /// </summary>
        [TestMethod]
        public void Iso639_1Test()
        {
            var target = new TmdbTranslation();
            string expected = Guid.NewGuid().ToString();
            string actual;
            target.Iso639_1 = expected;
            actual = target.Iso639_1;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Name
        /// </summary>
        [TestMethod]
        public void NameTest()
        {
            var target = new TmdbTranslation();
            string expected = Guid.NewGuid().ToString();
            string actual;
            target.Name = expected;
            actual = target.Name;
            Assert.AreEqual( expected, actual );
        }


        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\translation.json.txt")]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbTranslation();
            var jsonContent = File.ReadAllText("translation.json.txt");
            var actual = await target.DeserializeJson<TmdbTranslation>( jsonContent );

            Assert.AreEqual("English", actual.Name);
            Assert.AreEqual("English", actual.EnglishName);
            Assert.AreEqual( "en", actual.Iso639_1 );
        }
    }
}